package org.csu.mybigpro.controller;


import org.csu.mybigpro.service.LiveRecordingApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Controller
public class DemoController {

    // 注入 LiveRecordingApiService
    @Autowired
    private LiveRecordingApiService liveRecordingApiService;

    // 添加这个临时方法
    @GetMapping("/get-recording-token")
    @ResponseBody
    public String getRecordingToken() {
        try {
            // 使用反射调用私有方法 createApiToken()
            Method createApiTokenMethod = LiveRecordingApiService.class.getDeclaredMethod("createApiToken");
            createApiTokenMethod.setAccessible(true); // 允许访问私有方法
            return (String) createApiTokenMethod.invoke(liveRecordingApiService);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
            return "Error generating token: " + e.getMessage();
        }
    }

    @GetMapping("/demo")
    @ResponseBody
    public String demo() {
        return "hello demo...";
    }}
